<?php
session_start();
if(!isset($_SESSION['id'])){
    header('Location: login.php');
    exit;
}
?>
<!DOCTYPE html>
<html lang="en" class="no-js">
	<head>
		<meta charset="UTF-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 
		<meta name="viewport" content="width=device-width, initial-scale=1.0"> 
		<title>::: SOS UNITAU -- Sistema de ordem de serviço</title>
		
		<link rel="shortcut icon" href="img/logo.jpg">
		<link rel="stylesheet" type="text/css" href="css/normalize.css" />
		<link rel="stylesheet" type="text/css" href="css/demo.css" />
		<link rel="stylesheet" type="text/css" href="css/icons.css" />
		<link rel="stylesheet" type="text/css" href="css/style2.css" />
        <link rel="stylesheet" type="text/css" href="css/StylePage.css" />
        <link rel="stylesheet" type="text/css" href="css/default.css" />
        <link rel="stylesheet" type="text/css" href="css/component.css" />
        <script type="text/javascript" src="js/jquery1.6.min.js"></script>
        <script src="js/jquery.maskedinput-1.3.min.js"></script>
         
     <script>
        $(document).ready(function () {
            $('#novoNivel').click(function () {
                
                var nivel = $('#txtNivel').val().trim();

                if (nivel == "") {
                    alert('Preencha o nivel');
                } else {

                    $.post("../funcoes/novo_nivel.php", {nivel: nivel}, function (retorno) {
                        //                            alert(retorno.niveis[0]['id']);

                        window.opener.$('#txtNivel').find('option').remove();
                        window.opener.$('#txtNivel').append("<option value='0'>Selecione</option>");
                        $.each(retorno.niveis, function (key, value) {
                            //                                alert(value.id + " - " + value.nome);
                            window.opener.$('#txtNivel').append("<option value='" + value.id + "'>" + value.descricao + "</option>");
                        });
                        $("txtNivel").val("");
                        alert('Nivel Cadastrado com sucesso!');
                        window.self.close();
                    }, "json").fail(function () {
                        alert("erro");
                    });
                }
            });
        });
    </script>
         
         
</head>
<body style="overflow-x: hidden">
	 <form name="adicionarNiveis" id="adicionarNiveis" method="post" enctype="multipart/form-data" action="" class="style-form">
            	
                <fieldset style="width:30px;">
                	<legend>Novo nível: </legend>
                    <table width="800px" class="table-form">
            	<tr>
            			<td> <label for="txtNivel"> Adicionar Nível: </label> </td>
            			<td> <input name="txtNivel" id="txtNivel" type="text" required placeholder="Ex: Administrador" /></td>
            		</tr>
            
                    
            	</table>
                        <input type="button" value="Gravar" id="novoNivel" class="botao"  style="display:inline-block; margin-left:50%; margin-top:3%;" />
                        <input type="button" value="Cancelar" style="margin-left:5%;" onClick="javascript:c=window.confirm('Deseja Realmente cancelar?');if(c==true){self.close();}else{}" class="botao" />    
                	
                </fieldset>

		</form>


</body>
</html>